package io.a2a.service;

import io.a2a.spec.AgentCard;
import io.a2a.spec.AgentCapabilities;
import io.a2a.spec.AgentProvider;
import java.util.Arrays;
import java.util.Collections;

/**
 * AI服务类，用于管理和获取AgentCard
 */
public class AiService {
    private String serverAddr;
    private String username;
    private String password;
    private String namespace;
    
    public AiService(String serverAddr, String username, String password, String namespace) {
        this.serverAddr = serverAddr;
        this.username = username;
        this.password = password;
        this.namespace = namespace;
    }
    
    /**
     * 根据名称获取AgentCard
     * @param name AgentCard名称
     * @return AgentCard实例
     */
    public AgentCard getAgentCard(String name) {
        // 模拟从Nacos获取AgentCard的逻辑
        if ("asurada".equals(name)) {
            return createAsuradaAgentCard();
        }
        throw new RuntimeException("AgentCard not found: " + name);
    }
    
    private AgentCard createAsuradaAgentCard() {
        AgentProvider provider = new AgentProvider("Alibaba", "https://www.alibaba.com");
        
        AgentCapabilities capabilities = new AgentCapabilities.Builder()
                .streaming(true)
                .pushNotifications(false)
                .stateTransitionHistory(true)
                .extensions(Collections.emptyList())
                .build();
        
        return new AgentCard.Builder()
                .name("asurada")
                .description("Asurada AI Agent for intelligent conversations")
                .url("http://localhost:8080/agent/asurada")
                .provider(provider)
                .version("1.0.0")
                .documentationUrl("https://docs.alibaba.com/asurada")
                .capabilities(capabilities)
                .defaultInputModes(Arrays.asList("text"))
                .defaultOutputModes(Arrays.asList("text"))
                .skills(Collections.emptyList())
                .supportsAuthenticatedExtendedCard(false)
                .securitySchemes(Collections.emptyMap())
                .security(Collections.emptyList())
                .iconUrl("https://example.com/asurada-icon.png")
                .additionalInterfaces(Collections.emptyList())
                .preferredTransport("http")
                .protocolVersion("1.0")
                .build();
    }
}